<?php
define('FPDF_FONTPATH','font/');
require_once('fpdf.php');
require_once('gisp_admincon.php');
require_once('qrcode.class.php');
require_once("Connections/coneccionRatania.php");
require_once("Connections/funciones_pg.php");
//include_once('rotation.php');



	
	
class PDF extends FPDF{

/*
var $widths;
var $aligns;
var $angle=0;
var $javascript;
var $n_js;

function SetWidths($w)
{
    //Set the array of column widths
    $this->widths=$w;
}

function SetAligns($a)
{
    //Set the array of column alignments
    $this->aligns=$a;
}

function Row($data)
{
    //Calculate the height of the row
    $nb=0;
    for($i=0;$i<count($data);$i++)
        $nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
    $h=5*$nb;
    //Issue a page break first if needed
    $this->CheckPageBreak($h);
    //Draw the cells of the row
    for($i=0;$i<count($data);$i++)
    {
        $w=$this->widths[$i];
        $a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'L';
        //Save the current position
        $x=$this->GetX();
        $y=$this->GetY();
        //Draw the border
        $this->Rect($x,$y,$w,$h);
        //Print the text
        $this->MultiCell($w,5,$data[$i],0,$a);
        //Put the position to the right of the cell
        $this->SetXY($x+$w,$y);
    }
    //Go to the next line
    $this->Ln($h);
}

function CheckPageBreak($h)
{
    //If the height h would cause an overflow, add a new page immediately
    if($this->GetY()+$h>$this->PageBreakTrigger)
        $this->AddPage($this->CurOrientation);
}

function NbLines($w,$txt)
{
    //Computes the number of lines a MultiCell of width w will take
    $cw=&$this->CurrentFont['cw'];
    if($w==0)
        $w=$this->w-$this->rMargin-$this->x;
    $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
    $s=str_replace("\r",'',$txt);
    $nb=strlen($s);
    if($nb>0 and $s[$nb-1]=="\n")
        $nb--;
    $sep=-1;
    $i=0;
    $j=0;
    $l=0;
    $nl=1;
    while($i<$nb)
    {
        $c=$s[$i];
        if($c=="\n")
        {
            $i++;
            $sep=-1;
            $j=$i;
            $l=0;
            $nl++;
            continue;
        }
        if($c==' ')
            $sep=$i;
        $l+=$cw[$c];
        if($l>$wmax)
        {
            if($sep==-1)
            {
                if($i==$j)
                    $i++;
            }
            else
                $i=$sep+1;
            $sep=-1;
            $j=$i;
            $l=0;
            $nl++;
        }
        else
            $i++;
    }
    return $nl;
}    
  */  


	function IncludeJS($script) {
		$this->javascript=$script;
	}

	function _putjavascript() {
		$this->_newobj();
		$this->n_js=$this->n;
		$this->_out('<<');
		$this->_out('/Names [(EmbeddedJS) '.($this->n+1).' 0 R]');
		$this->_out('>>');
		$this->_out('endobj');
		$this->_newobj();
		$this->_out('<<');
		$this->_out('/S /JavaScript');
		$this->_out('/JS '.$this->_textstring($this->javascript));
		$this->_out('>>');
		$this->_out('endobj');
	}


function AutoPrint($dialog=false)
{
	//Open the print dialog or start printing immediately on the standard printer
	$param=($dialog ? 'true' : 'false');
	$script="print($param);";
	$this->IncludeJS($script);
}

function AutoPrintToPrinter($server, $printer, $dialog=false)
{
	//Print on a shared printer (requires at least Acrobat 6)
	$script = "var pp = getPrintParams();";
	if($dialog)
		$script .= "pp.interactive = pp.constants.interactionLevel.full;";
	else
		$script .= "pp.interactive = pp.constants.interactionLevel.automatic;";
	$script .= "pp.printerName = '\\\\\\\\".$server."\\\\".$printer."';";
	$script .= "print(pp);";
	$this->IncludeJS($script);
}


	function _putresources() {
		parent::_putresources();
		if (!empty($this->javascript)) {
			$this->_putjavascript();
		}
	}

	function _putcatalog() {
		parent::_putcatalog();
		if (!empty($this->javascript)) {
			$this->_out('/Names <</JavaScript '.($this->n_js).' 0 R>>');
		}
	}
	

function Rotate($angle,$x=-1,$y=-1)
{
	if($x==-1)
		$x=$this->x;
	if($y==-1)
		$y=$this->y;
	if($this->angle!=0)
		$this->_out('Q');
	$this->angle=$angle;
	if($angle!=0)
	{
		$angle*=M_PI/180;
		$c=cos($angle);
		$s=sin($angle);
		$cx=$x*$this->k;
		$cy=($this->h-$y)*$this->k;
		$this->_out(sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy));
	}
}

function _endpage()
{
	if($this->angle!=0)
	{
		$this->angle=0;
		$this->_out('Q');
	}
	parent::_endpage();
}

function RotatedText($x,$y,$txt,$angle)
{
    //Text rotated around its origin
    $this->Rotate($angle,$x,$y);
    $this->Text($x,$y,$txt);
    $this->Rotate(0);
}

function RoundedRect($x, $y, $w, $h, $r, $style = '')
    {
        $k = $this->k;
        $hp = $this->h;
        if($style=='F')
            $op='f';
        elseif($style=='FD' || $style=='DF')
            $op='B';
        else
            $op='S';
        $MyArc = 4/3 * (sqrt(2) - 1);
        $this->_out(sprintf('%.2F %.2F m',($x+$r)*$k,($hp-$y)*$k ));
        $xc = $x+$w-$r ;
        $yc = $y+$r;
        $this->_out(sprintf('%.2F %.2F l', $xc*$k,($hp-$y)*$k ));

        $this->_Arc($xc + $r*$MyArc, $yc - $r, $xc + $r, $yc - $r*$MyArc, $xc + $r, $yc);
        $xc = $x+$w-$r ;
        $yc = $y+$h-$r;
        $this->_out(sprintf('%.2F %.2F l',($x+$w)*$k,($hp-$yc)*$k));
        $this->_Arc($xc + $r, $yc + $r*$MyArc, $xc + $r*$MyArc, $yc + $r, $xc, $yc + $r);
        $xc = $x+$r ;
        $yc = $y+$h-$r;
        $this->_out(sprintf('%.2F %.2F l',$xc*$k,($hp-($y+$h))*$k));
        $this->_Arc($xc - $r*$MyArc, $yc + $r, $xc - $r, $yc + $r*$MyArc, $xc - $r, $yc);
        $xc = $x+$r ;
        $yc = $y+$r;
        $this->_out(sprintf('%.2F %.2F l',($x)*$k,($hp-$yc)*$k ));
        $this->_Arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r);
        $this->_out($op);
    }

    function _Arc($x1, $y1, $x2, $y2, $x3, $y3)
    {
        $h = $this->h;
        $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $x1*$this->k, ($h-$y1)*$this->k,
            $x2*$this->k, ($h-$y2)*$this->k, $x3*$this->k, ($h-$y3)*$this->k));
    }
	
	function Header(){
		//datos SQL
		global $login;
		global $centro_costo;
		global $nom_oficina;
		global $cod_actproy;
		global $des_actproy;
		global $cod_nemonico;
		global $des_nemonico;
		global $title;
		global $nro_nec;
		global $ano_eje;
		global $fch_nec;
		global $tipo_bien;
		global $reqs_anuales;			
		global $topIni;
		global $marIni;
		global $wcel;
		global $empresaM;
		global $distrito;
		global $departamento;
		global $provincia;
		global $logoCabIzq;
		global $logoSupP1;
		global $logoSupP2;
		global $logoSupP3;
		global $logoSupP4;
		global $marcaAguaP1;
		global $marcaAguaL1;
		global $marcaAguaL2;
		global $marcaAguaL3;
		global $marcaAguaL4;global $marcaAguaP2;
		global $marcaAguaP3;
		global $marcaAguaP4;
		global $marcaDeAgua;
		global $repositorioFirmas;
		global $RUC;
		global $numero_recibo;
		global $codigoContrib;
		global $nombreContrib;
		global $nroDoc;
		global $direccionContrib;
		global $cajero;
		global $fechaEmision;
		global $fechaImpresion;
		global $fechaProyectado1;
		global $err;
		global $fechaRecargos;
		global $usuario;
		global $colCab;
		global $colSubCab;
		global $tituloHR1;
                global $tituloHR2;
                global $tituloHR3;
                global $tituloHR4;
                global $p_nroDoc;
                global $direcreferencia;
                global $disdirfiscal;
                global $documento;
                global $vusuario; 
                global $fechareg; 
                
                global $p_nautova;
                global $p_nbaseim;
                global $p_nimpanu;
                global $p_ncosemi;
                global $p_totalPagar;
                global $p_nvaluit;
                global $IEmision;
                
		
		
		$lw = $marIni;
		$ln = $topIni;
		$ls = 3;
		$lh = 0;
		//MArca de Agua
		$this->Image('../img/marca/escudomarcaagua4.png',$marcaAguaL1-20,$marcaAguaL2-65,$marcaAguaL3+40,$marcaAguaL4+40,'PNG');
		
		//Logo
		$this->SetFont('narrow','',8);
		//$this->SetFillColor(206,232,212); //verde agua
		$this->SetFillColor(188,217,190); //verde agua
		$this->SetXY($lw-10,$lh);
		$this->Cell(220,6,"",0,1,'L',true);
		$this->SetFillColor(243);
		$this->SetFont('arial','B',9);
		$this->SetXY($lw-10,$lh);
		$this->MultiCell(50,6,'Calle 9 de Junio Nro 100',1,'C');
		$this->SetXY($lw+40,$lh);
		$this->MultiCell(50,6,'Puente Piedra - Lima - Peru',1,'C');
		$this->SetXY($lw+90,$lh);
		$this->MultiCell(50,6,'www.munipuentepiedra.gob.pe',1,'C');
		$this->SetXY($lw+140,$lh);
		$this->MultiCell(60,6,'Telefono 219 6200 - 219 6201',1,'C');
		//$this->RoundedRect(-10, 0, 220, 8, 1,'S');
		$this->Image('../img/marca/munipuentepiedra.png',$lw,$ln-3,52,15,'PNG');
		
		//$this->SetFillColor(145,185,154); //verde agua
		$this->SetFillColor(255);
		$lh = $lh+6;
		$this->SetXY($lw+70,$lh);
		$this->Cell(160,12,"",0,1,'L',true);
		$this->SetFont('arial','B',12);
		$this->SetXY($lw+35,$lh);
		$this->MultiCell(160,10,$tituloHR1,0,'C');
                /*$this->SetXY($lw+65,$lh+4);
		$this->MultiCell(100,10,$tituloHR2,0,'C');*/
                $this->SetXY($lw+35,$lh+4);
                $this->SetFont('narrow','',8);
		$this->MultiCell(160,10,$tituloHR3,0,'C');
                $this->SetXY($lw+35,$lh+8);
                $this->SetFont('arial','B',12);
		$this->MultiCell(160,10,$tituloHR4,0,'C');
		
                if($IEmision==false){
                    $this->SetXY($lw+150,$lh);
                    $this->SetFont('arial','B',20);
                    $this->MultiCell(60,10,'HLP',0,'C');
                }else{
                    
                    $this->SetXY($lw+170,$lh);
                    $this->SetFont('arial','B',20);
                    //$this->Cell(10,8,"",1,1,'L',true);
                    $this->SetXY($lw+170,$lh);
                    $this->MultiCell(20,8,'HLP',0,'C');
                    $this->SetFillColor(188,217,190); //verde agua
                    $this->SetXY($lw+190,$lh);
                    $this->Cell(10,8,"",1,1,'L',true);
                    $this->SetFont('f25bankprinter','',20);
                    $this->SetXY($lw+182,$lh);
                    $this->MultiCell(10,8,'4',0,'L');
                     $this->SetFillColor(255,255,255); //Negro
                 }
                $this->SetXY($lw+150,$lh+4);
                $this->SetFont('arial','B',6);
		$this->MultiCell(60,10,'(Hoja Liquidacion Predial)',0,'C');
                $this->SetXY($lw+150,$lh+7);
                $this->SetFont('arial','B',11);
		$this->MultiCell(60,10,$p_nroDoc,0,'C');
		
                
		//definimos  ancho y color de rectangulo
		$lh = $lh+17;
		
		$nombreContrib1=utf8_decode($nombreContrib);
		$this->SetLineWidth(0.3);
		$this->SetFillColor(255);
		
                $this->RoundedRect($lw-5, $lh, 110, 24, 1, '');
		 if(strlen(trim($nombreContrib1))>45 and strlen(trim($nombreContrib1))<=60){
                   $this->SetFont('narrow','',10); 
                }elseif(strlen(trim($nombreContrib1))>60 and strlen(trim($nombreContrib1))<=90 ){
                    $this->SetFont('narrow','',8);
                    
                }elseif(strlen(trim($nombreContrib1))>90){
                    $this->SetFont('narrow','',6);
                    
                }else{
                    $this->SetFont('narrow','',12); 
                }
		$this->SetXY($lw-5,$lh+2);
		$this->MultiCell(110,3,trim(utf8_decode($nombreContrib1)),0,'L');
		$this->SetFont('narrow','',8);
		$this->SetXY($lw-5,$lh+10);
		$this->MultiCell(110,4,trim(utf8_decode($documento)),0,'L');
                $this->SetXY($lw-5,$lh+14);
                $this->SetFont('narrow','',8);
		$this->MultiCell(110,4,trim(utf8_decode($direccionContrib.' - '.$disdirfiscal)),0,'L');
                $this->SetFont('narrow','',7);
		$this->SetXY($lw-5,$lh+19);
		$this->MultiCell(110,4,trim(utf8_decode($direcreferencia)),0,'L');
                
		
		//$qrcode = new QRcode(utf8_encode('Hola'), $err);
		//$qrcode->disableBorder();
		
		//aqui va el codigo de barras
		//$qrcode->displayHTML();
		//$this->SetXY($lw+10,$lh+12);
		//$qrcode->displayPNG(50);
		//$this->Image(,$lw,$ln,62,18,'PNG');
		
		//$this->SetXY($lw,$lh + 17 );
		//$this->Image('../img/marca/barraBoucher_2dat.gif',$lw-3,$lh+6,13,13,'GIF','');
		
		
                //$this->RoundedRect($lw+110, $lh, 85, 20, 1, '');
		$this->SetFont('arial','B',8);
		$this->SetXY($lw+110,$lh);
		$this->Cell(42,4,"",1,1,'L',true);
		$this->SetXY($lw+112,$lh);
		$this->MultiCell(40,4,'Codigo Contribuyente',0,'J');
		$this->SetXY($lw+152,$lh);
		$this->Cell(43,4,"",1,1,'L',true);
		$this->SetXY($lw+152,$lh);
		$this->SetFont('f25bankprinter','',10);
		$this->MultiCell(43,4,$codigoContrib,0,'R');
		
		$this->SetFont('arial','',8);
		$this->SetXY($lw+110,$lh+4);
		$this->Cell(42,4,"",1,1,'L',true);
		$this->SetXY($lw+112,$lh+4);
		$this->MultiCell(40,4,'Fecha Registro',0,'J');
		$this->SetXY($lw+152,$lh+4);
		$this->Cell(43,4,"",1,1,'L',true);
		$this->SetXY($lw+152,$lh+4);
		$this->SetFont('f25bankprinter','',10);
		$this->MultiCell(43,4,$fechareg,0,'R');
		
		
		$this->SetFont('arial','',8);
		$this->SetXY($lw+110,$lh+8);
		$this->Cell(42,4,"",1,1,'L',true);
		$this->SetXY($lw+112,$lh+8);
		$this->MultiCell(40,4,'Usuario Registro',0,'J');
		$this->SetXY($lw+152,$lh+8);
		$this->Cell(43,4,"",1,1,'L',true);
		$this->SetXY($lw+152,$lh+8);
		$this->SetFont('f25bankprinter','',10);
		$this->MultiCell(43,4,$vusuario,0,'R');
                
                $this->SetFont('arial','',8);
		$this->SetXY($lw+110,$lh+12);
		$this->Cell(42,4,"",1,1,'L',true);
		$this->SetXY($lw+112,$lh+12);
		$this->MultiCell(40,4,'Usuario Impresion',0,'J');
		$this->SetXY($lw+152,$lh+12);
		$this->Cell(43,4,"",1,1,'L',true);
		$this->SetXY($lw+152,$lh+12);
		$this->SetFont('f25bankprinter','',10);
		$this->MultiCell(43,4,$usuario,0,'R');
		
		$this->SetFont('arial','',8);
		$this->SetXY($lw+110,$lh+16);
		$this->Cell(42,4,"",1,1,'L',true);
		$this->SetXY($lw+112,$lh+16);
		$this->MultiCell(40,4,'Fecha Impresion',0,'J');
		$this->SetXY($lw+152,$lh+16);
		$this->Cell(43,4,"",1,1,'L',true);
		$this->SetXY($lw+152,$lh+16);
		$this->SetFont('f25bankprinter','',8);
		$this->MultiCell(43,4,$fechaImpresion,0,'R');
		
                
                $lh = $lh +25;
		
		
                $this->SetFillColor(188,217,190); //verde agua
                $ls=-5;
		$this->SetFont('narrow','',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colCab[3]*2,4,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh);
		$this->MultiCell($colCab[3]*2,4,'TRAMOS DEL AUTOVALUO',1,'C');
		
		/*
                 * CALCULAMOS LOS TRAMOS UIT
                 */
                if($p_nbaseim<=($p_nvaluit*15)){
                    $p_enuit = '15 UITs';
                    $p_UitSoles = $p_nvaluit*15;
                    $p_alicuota = '0.2%';
                }elseif($p_nbaseim>($p_nvaluit*15) and $p_nbaseim<=($p_nvaluit*60)){
                    $p_enuit = '60 UITs';
                    $p_UitSoles = 60*$p_nvaluit;
                    $p_alicuota = '0.6%';
                }elseif( $p_nbaseim>($p_nvaluit*60)){
                    $p_enuit = '+60 UITs';
                    $p_UitSoles = 60*$p_nvaluit;
                    $p_alicuota = '0.1%';
                }
		
		$this->SetFont('narrow','',8);
		$this->SetXY($lw+$ls,$lh+4);
		$this->Cell($colCab[3],4,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+4);
		$this->MultiCell($colCab[3],4,'EN UIT',1,'C');
                
                $ls = $colCab[3]-5;
                
                $this->SetFont('narrow','',8);
		$this->SetXY($lw+$ls,$lh+4);
		$this->Cell($colCab[3],4,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+4);
		$this->MultiCell($colCab[3],4,'EN S/.',1,'C');

                
                
                
		$ls = $colCab[3]*2-5;
		$this->SetFont('narrow','',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colCab[3],8,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh);
		$this->MultiCell($colCab[3],8,'ALICUOTA',1,'C');
                
                $ls = $colCab[3]*3-5;
		$this->SetFont('narrow','',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colCab[5],8,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh);
		$this->MultiCell($colCab[5],8,'BASE IMPONIBLE POR TRAMOS',1,'C');
	
		
		$ls = $colCab[3]*3+$colCab[5]-5;
		$this->SetFont('narrow','',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colCab[3],8,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh);
		$this->MultiCell($colCab[3],8,'AUTOVALUO',1,'C');
                
                $this->SetFillColor(255);
                
                $lh+=8;
                $ls=-5;
                $this->SetFont('narrow','',8);
		$this->SetXY($lw+$ls,$lh);
		//$this->Cell($colCab[1],5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh);
		$this->MultiCell($colCab[3],4,$p_enuit,1,'C');
                
                $ls = $colCab[3]-5;
                
                $this->SetFont('narrow','',8);
		$this->SetXY($lw+$ls,$lh);
		//$this->Cell($colCab[1],5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh);
		$this->MultiCell($colCab[3],4,$p_UitSoles,1,'C');

                
                
                
		$ls = $colCab[3]*2-5;
		$this->SetFont('narrow','',8);
		$this->SetXY($lw+$ls,$lh);
		//$this->Cell($colCab[2],5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh);
		$this->MultiCell($colCab[3],4,$p_alicuota,1,'C');
                
                $ls = $colCab[3]*3-5;
		$this->SetFont('narrow','',8);
		$this->SetXY($lw+$ls,$lh);
		//$this->Cell($colCab[2],5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh);
		$this->MultiCell($colCab[5],4,  number_format($p_nbaseim,2,',',' '),1,'C');
	
		
		$ls = $colCab[3]*3+$colCab[5]-5;
		$this->SetFont('narrow','',8);
		$this->SetXY($lw+$ls,$lh);
		//$this->Cell($colCab[3],5,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh);
		$this->MultiCell($colCab[3],4,number_format($p_totalPagar,2,',',' '),1,'C');
                
                
                $this->SetFillColor(188,217,190); //verde agua
                $lh+=4;
                $ls=-5;
                $this->SetFont('narrow','',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colCab[3],8,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh);
		$this->MultiCell($colCab[3],8,'CUOTA TRIMESTRAL',1,'C');
                
                $ls = $colCab[3]-5;
                
                $this->SetFont('narrow','',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colCab[3],8,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh);
		$this->MultiCell($colCab[3],8,'VENCIMIENTO',1,'C');

                
                
                
		$ls = $colCab[3]*2-5;
		$this->SetFont('narrow','',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colCab[3]*3,4,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh);
		$this->MultiCell($colCab[3]*3,4,'IMPORTE (S/.)',1,'C');
                
                $this->SetFont('narrow','',8);
		$this->SetXY($lw+$ls,$lh+4);
		$this->Cell($colCab[3],4,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+4);
		$this->MultiCell($colCab[3],4,'INSOLUTO',1,'C');
                
                $ls = $colCab[3]*3-5;
                $this->SetFont('narrow','',8);
		$this->SetXY($lw+$ls,$lh+4);
		$this->Cell($colCab[3],4,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+4);
		$this->MultiCell($colCab[3],4,'EMISION',1,'C');
                
                $ls = $colCab[3]*4-5;
                $this->SetFont('narrow','',8);
		$this->SetXY($lw+$ls,$lh+4);
		$this->Cell($colCab[3],4,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh+4);
		$this->MultiCell($colCab[3],4,'IMPORTE TOTAL',1,'C');
                
                
                
                
                
                $ls = $colCab[3]*5-5;
		$this->SetFont('narrow','',8);
		$this->SetXY($lw+$ls,$lh);
		$this->Cell($colCab[6],8,"",1,1,'L',true);
		$this->SetXY($lw+$ls,$lh);
		$this->MultiCell($colCab[6],8,'Nro RECIBO',1,'C');
	
				
		
	}
	
	function Footer(){
		
                /*
                global $marini;
		global $nro_nec;
		global $ano_eje;
		global $nombreGispAdmincon;
                global $style;
                global $lp;
                global $p_nautova;
                global $p_nbaseim;
                global $p_nimpanu;
                global $p_ncosemi;
                global $p_totalPagar;
                
                
                $h1 = -35;
                $h2 = -35;
                $x = $marini+5;
                $this->SetXY($x,$h1 );
		//$var1 = $this->GetY();
		//if($corte = $this->CheckPageBreak($var1)) $h = $lp;
		$this->SetFont('Arial','',8);
		$hh = $lp+20;
                $this->RoundedRect($x+90, $hh+4, 20, 25, 1, '');
		$Texto = "(*) Predio Descargado";
		$this->SetXY($x,$h1);
		$this->MultiCell(60,4,$Texto,0,'J');
                
                $hh = $lp+36;
                $Texto = "Firma del Propietario o Representante Legal";
		$this->SetXY($x,$h1+=18);
                $this->Line($x, $hh-1 , 85, $hh-1, $style);
		$this->MultiCell(60,4,$Texto,0,'J');
                
                $Texto = "Nombre : ";
		$this->SetXY($x,$h1+=5);
                $this->Line($x+16, $hh+7 , 85, $hh+7, $style);
		$this->MultiCell(15,3,$Texto,0,'R');
                $Texto = "DNI : ";
		$this->SetXY($x,$h1+=5);
                $this->Line($x+16, $hh+12 , 85, $hh+12, $style);
		$this->MultiCell(15,3,$Texto,0,'R');
                
                $h2 = $h2;
                $Texto = "Total de Autovaluo : ";
		$this->SetXY($x+140,$h2);
		$this->MultiCell(30,4,$Texto,0,'R');
                $this->SetXY($x+170,$h2);
		$this->MultiCell(30,4,  number_format($p_nautova,'2',',',' '),1,'R');
                $Texto = "Base Imponible : ";
		$this->SetXY($x+140,$h2+=4);
		$this->MultiCell(30,4,$Texto,0,'R');
                $this->SetXY($x+170,$h2);
		$this->MultiCell(30,4,number_format($p_nbaseim,'2',',',' '),1,'R');
                $Texto = "Impuesto Predial : ";
		$this->SetXY($x+140,$h2+=4);
		$this->MultiCell(30,4,$Texto,0,'R');
                $this->SetXY($x+170,$h2);
		$this->MultiCell(30,4,number_format($p_nimpanu,'2',',',' '),1,'R');
                $Texto = "Gastos de Emision : ";
		$this->SetXY($x+140,$h2+=4);
		$this->MultiCell(30,4,$Texto,0,'R');
                $this->SetXY($x+170,$h2);
		$this->MultiCell(30,4,number_format($p_ncosemi,'2',',',' '),1,'R');
                $Texto = "Total a Pagar : ";
		$this->SetXY($x+140,$h2+=4);
		$this->MultiCell(30,4,$Texto,0,'R');
                $this->SetXY($x+170,$h2);
		$this->MultiCell(30,4,number_format($p_totalPagar,'2',',',' '),1,'R');
                  
               
                 */
                $lh=-20;
                $lw = $marini+5;
                $this->SetXY($lw+$ls,$lh);
		$texto = utf8_decode("Consultas: Línea de Atención Tributaria 219-6219, 219-6230, 219-6200 y/o a nuestro correo electrónico serviciosalciudadano@munipuentepiedra.gob.pe ");
                $this->MultiCell(100,5,$texto,0,'L');
                
                $this->SetXY($lw+$ls+100,$lh);
		$texto = utf8_decode("GERENCIA DE ADMINISTRACION TRIBUTARIA ");
                $this->MultiCell(100,5,$texto,0,'R');
	}
	
	function WriteResumen($x,$h1, $corte,$topmar){
		//datos SQL
		global $Coneccion;
                global $lp;

		//datos DOC
		global $marini;
		global $topmar;
		global $repositorioFirmas;
		
                
		
	}
	
	function CheckPageBreak($h){
		if($h >= 105){
			$this->AddPage();	
			return 1;
		}else{
			$this->SetY($h);
			return 0;
		}
		/*if($h >= 250){
			$this->AddPage('P','mm','A4');
			return true;
		}*/
	}
	
	
}


$usuario = $_GET['usuario'];
$contrib =  $_GET['p_mperson'];
$p_mhresum =  $_GET['p_mhresum'];
$predio =  $_GET['p_ccodpre'];
$IEmision = $_GET['IEmision'];

$nro_contrib = $_GET['p_mperson'];
$p_cperiod = $_GET['p_cperiod'];
//$p_cperiod = '2014';


$periodos = explode('-',$p_cperiod);
$periodos= array_unique($periodos);
$p_cperiod = "2014";
$NPeriodos = count($periodos);
//echo "PERIODOS ".$NPeriodos." PERIDDITO ".  var_dump($periodos);
//die();
$filtroConsulta = "";
if($p_mhresum<>'-1'){
    $filtroConsulta = " AND t1.idsigma='".$p_mhresum."'";
}  else {
    $filtroConsulta = " AND t1.nestado='1'";
}

$Rs_grabarCAB = new TSPResult($ConeccionRatania,"");
$Rs_grabarCAB->Poner_MSQL("select t1.idsigma as mhresum_actual, 
t1.ctipdat as tipo, 
( select  public.mconten.vdescri from public.mconten WHERE idsigma=t1.cmotivo) as motivo, 
t1.vnrodoc as dj,
(t2.vpatern||' '||t2.vmatern||' '||t2.vnombre) as nombrecontrib,
(t2.cdenomi||' '||t2.vdirecc||' '||t2.vnumero||' '||t2.vmanzan||' '||t2.vlote) dirfiscal,
t2.vreferen as refdirfiscal,
(select vnombres from registro.mubigeo WHERE idsigma=t2.mubigeo) as disdirfiscal,
( COALESCE((select public.mconten.vdescri from public.mconten WHERE idsigma=t2.ctipdoc),' DNI ') )||' '||COALESCE(t2.vnrodoc,'') as documento,
t2.idsigma as cidpers,
(COALESCE((select u.usuario from seguridad.usuario as u  where u.cidusuario=t1.vusernm),t1.vusernm) ) as vusuario,
t1.ddatetm as fechareg
from registro.mhresum as t1,
public.mperson as t2
where 
t1.mperson=t2.idsigma
AND t1.mperson='".$nro_contrib."'
$filtroConsulta

");
$Rs_grabarCAB->pg_Poner_Esquema("tesoreria");

$Rs_grabarCAB->executeMSQL();


//echo "<br><br>CONSULTA REQ UPDATE <br> ".$Rs_grabarCAB->Escribir_Consulta();

$NCAB = 0;
$numRowsCAB = $Rs_grabarCAB->pg_Num_Rows();
//echo $numRowsCAB;
while($NCAB < $numRowsCAB){

    
//echo "HOLAAAAAAAAAAAAAAAA";
//echo "<br><br>CONSULTA REQ UPDATE <br> ".$Rs_grabar->Escribir_Consulta();			
$rowCAB= $Rs_grabarCAB->pg_Get_Row();


$RUC='20131366702';
$numero_recibo='860100100014';
$codigoContrib=$rowCAB['cidpers'];
$mhresum_actual=$rowCAB['mhresum_actual'];
$nombreContrib=$rowCAB['nombrecontrib'];
$direccionContrib=$rowCAB['dirfiscal'];
$direcreferencia=$rowCAB['refdirfiscal'];
$disdirfiscal=$rowCAB['disdirfiscal'];
$documento=$rowCAB['documento']; 
$vusuario=$rowCAB['vusuario']; 
$fechareg=$rowCAB['fechareg']; 
$c_motivo = $rowCAB['motivo'];
$c_nrodj = $rowCAB['dj'];

$p_cperiod ='2014';

$TipoCabecera='1';


$tituloHR1 = "LIQUIDACION DEL IMPUESTO PREDIAL ".$p_cperiod;
$tituloHR2 = "IMPUESTO PREDIAL ".$p_cperiod;
$tituloHR3 = "T.U.O DE LA LEY TRIBUTACION MUNICIPAL";
$tituloHR4 = utf8_decode( "(D.S. N° 156-2014-EF) ");
$p_nroDoc = "2014001452";
$p_nroDoc = "Nro ".$c_nrodj;
//$cajero='NDIESTRO';
//$usuario='NDIESTRO';
//$fechaEmision='12-12-2013 15:56';

//echo 'HOLA '.$fechaProyectado ;
//echo 'USUARIO '.$usuario ;


$Rs_grabar = new TSPResult($ConeccionRatania,"");
$Rs_grabar->Poner_MSQL("SELECT t1.nvaluit
FROM public.cvaluit as t1
WHERE t1.cperiod='".$p_cperiod."'
    ");
$Rs_grabar->pg_Poner_Esquema("tesoreria");

$Rs_grabar->executeMSQL();

$row= $Rs_grabar->pg_Get_Row();
$p_nvaluit = $row['nvaluit'];

$Rs_grabar = new TSPResult($ConeccionRatania,"");
$Rs_grabar->Poner_MSQL("SELECT t1.nautova,t1.nbaseim,t1.nimpanu,t1.ncosemi
FROM registro.dresumn as t1
WHERE t1.cperiod='".$p_cperiod."'
AND t1.mhresum='".$mhresum_actual."' 
    ");
$Rs_grabar->pg_Poner_Esquema("tesoreria");

$Rs_grabar->executeMSQL();

$row= $Rs_grabar->pg_Get_Row();
$p_nautova = $row['nautova'];
$p_nbaseim = $row['nbaseim'];
$p_nimpanu = $row['nimpanu'];
$p_ncosemi = $row['ncosemi'];
$p_ncosemi = $row['ncosemi'];
$p_totalPagar = $row['nimpanu'];


$Rs_grabar = new TSPResult($ConeccionRatania,"");
$Rs_grabar->Poner_MSQL("SELECT sum(t1.imp_insol) as total,
    to_char(t1.dfecven,'dd/mm/YYYY') as dfecven,
    sum(t1.costo_emis) as costo_emis,
    t1.cperiod
    FROM tesoreria.mestcta as t1
    WHERE t1.cidpers='".$codigoContrib."'
        AND cperanio='".$p_cperiod."'
        AND t1.ctiping='0000000273'
        AND t1.ctiprec='0000000273'
        AND t1.mhresum='".$mhresum_actual."' 
            GROUP BY 2,4
            ORDER BY 4
    ");
$Rs_grabar->pg_Poner_Esquema("tesoreria");
//echo $Rs_grabar->Escribir_Consulta();
$Rs_grabar->executeMSQL();



date_default_timezone_set('America/Lima');
$fechaImpresion=strftime('%d/%m/%Y %H:%M:%S'); 
//$nroDoc='42215638';
//$fechaProyectado = '13/12/2013';
//$fechaRecargos = '13/12/2013';
if (!in_array($err, array('L', 'M', 'Q', 'H'))) $err = 'Q';

$colCab = array('22','134','14','35','220','60','25');
$colSubCab[0] = array('35','8','18');
$colSubCab[1] = array('18','20','25');
$colSubCab[2] = array('18','8','25');

$topIni = 10;
$marIni = 10; 
$topmar = 68;
$lp = 96;
//$lw=10;

$pdf = new PDF('L','mm','A5');
$pdf->SetDisplayMode('fullpage');
//$pdf->AutoPrint();

$pdf->AliasNbPages();
$pdf->AddPage();
//$pdf->SetBottonMargin(140);
$pdf->SetFont('Arial','B',16);

$lw = $marIni;
$var1 = $topmar;
//$var1 = $topmar+5;
$pdf->SetXY($lw,$lh = $var1);


	$N = 0;
	$numRows = $Rs_grabar->pg_Num_Rows();
        $sumImpSol = 0;
        $sumCostoEmi = 0;
        
	while($N < $numRows){
		
		$row= $Rs_grabar->pg_Get_Row();
                
                $descargo = '';
                if(trim($row['nestado'])=='0'){
                    $descargo = '*';
                }
                
                $imp_insol = $row['total'];
                $dfecven = trim($row['dfecven']);
                $costo_emis = $row['costo_emis'];
                $cperiod = trim($row['cperiod']);
                $nrorecibo = trim($row['nrorecibo']);
                
                $sumImpSol +=$imp_insol;
                $sumCostoEmi +=$costo_emis;
                switch($cperiod){
                    case '01':
                        $param_cperiod='01 Trimestre';
                        break;
                    case '02':
                        $param_cperiod='02 Trimestre';
                        break;
                    case '03':
                        $param_cperiod='03 Trimestre';
                        break;
                    case '04':
                        $param_cperiod='04 Trimestre';
                        break;
                }
                $ls = -5;
                
                $pdf->SetFont('narrow','',10);
                $pdf->SetXY($lw+$ls,$lh);
		$pdf->MultiCell($colCab[3],5,$param_cperiod,1,'L');
                $ls += $colCab[3];
                $pdf->SetFont('narrow','',10);
                $pdf->SetXY($lw+$ls,$lh);
		$pdf->MultiCell($colCab[3],5,$dfecven,1,'C');
                $ls += $colCab[3];
                $pdf->SetXY($lw+$ls,$lh);
		$pdf->MultiCell($colCab[3],5,  number_format($imp_insol,'2',',',' '),1,'R');
                $ls += $colCab[3];
                $pdf->SetXY($lw+$ls,$lh);
		$pdf->MultiCell($colCab[3],5,number_format($costo_emis,'2',',',' '),1,'R');
                $ls += $colCab[3];
                $pdf->SetXY($lw+$ls,$lh);
		$pdf->MultiCell($colCab[3],5,number_format($imp_insol+$costo_emis,'2',',',' '),1,'R');
                $ls += $colCab[3];
                $pdf->SetXY($lw+$ls,$lh);
		$pdf->MultiCell($colCab[6],5,$nrorecibo,1,'R');
                
                $var1 = $pdf->GetY();
		if($corte = $pdf->CheckPageBreak($var1)) $lh = $topmar-5;
                
                $lh = $lh+5;
			$Rs_grabar->pg_Move_Next();
			$N++;
		}
                $ls = -5;
                
                $pdf->SetFont('Arial','B',10);
                $pdf->SetXY($lw+$ls,$lh);
		$pdf->MultiCell($colCab[3],5,'Cuota Anual',1,'C');
                $ls += $colCab[3];
                
                $pdf->SetXY($lw+$ls,$lh);
		$pdf->MultiCell($colCab[3],5,'28/02/2013',1,'C');
                $ls += $colCab[3];
                $pdf->SetXY($lw+$ls,$lh);
		$pdf->MultiCell($colCab[3],5,  number_format($sumImpSol,'2',',',' '),1,'R');
                $ls += $colCab[3];
                $pdf->SetXY($lw+$ls,$lh);
		$pdf->MultiCell($colCab[3],5,number_format($sumCostoEmi,'2',',',' '),1,'R');
                $ls += $colCab[3];
                $pdf->SetXY($lw+$ls,$lh);
		$pdf->MultiCell($colCab[3],5,number_format($sumImpSol+$sumCostoEmi,'2',',',' '),1,'R');
                $ls += $colCab[3];
                $pdf->SetXY($lw+$ls,$lh);
		$pdf->MultiCell($colCab[6],5,'',1,'R');
                
                $var1 = $pdf->GetY();
		if($corte = $pdf->CheckPageBreak($var1)) $lh = $topmar-5;
                
                $lh = $lh+6;
                $ls = -5;
                
                $pdf->SetFillColor(255);
                $pdf->SetFont('Arial','B',12);
                $pdf->SetXY($lw+$ls,$lh);
		$pdf->Cell($colCab[3]*5+$colCab[6],16,"",1,1,'L',true);
                $pdf->SetXY($lw+$ls,$lh);
		$pdf->MultiCell($colCab[3]*5+$colCab[6],5,'ORDENANZA 229-MDPP',0,'L');
                $lh+=5;
                $pdf->SetFont('narrow','',8);
                $pdf->SetXY($lw+$ls,$lh);
		$texto = utf8_decode("Los Contribuyentes y/o responsables que opten por la cancelación anual del Impuesto Predial y los Arbitrios Municipales del ejercicio 2014 (Limpieza Pública (recolección de residuos sólidos, barrido de calles), Parques y Jardines, Serenazgo) hasta el último día del mes de febrero, obtendrán un descuento del 30% del monto insoluto de los Arbitrios ");
                $pdf->MultiCell($colCab[3]*5+$colCab[6],5,$texto,0,'L');
                $lh+=11;
                $pdf->SetXY($lw+$ls,$lh);
		$pdf->Cell($colCab[3]*5+$colCab[6],8,"",1,1,'L',true);
                $pdf->SetFont('narrow','',8);
                $pdf->SetXY($lw+$ls,$lh);
		$texto = utf8_decode("Recuerde, si efectúa el Pago al contado, cancelando todo el Impuesto Predial hasta el 28 de febrero del 2013, no estará sujeto a la variación del índice de Precios al por Mayor ");
                $pdf->MultiCell($colCab[3]*5+$colCab[6],5,$texto,0,'L');
                $lh+=8;
                $pdf->SetXY($lw+$ls,$lh);
		$pdf->Cell($colCab[3]*5+$colCab[6],8,"",1,1,'L',true);
                $pdf->SetFont('narrow','',8);
                $pdf->SetXY($lw+$ls,$lh);
		$texto = utf8_decode("Usted puede efectuar el pago de sus tributos en las Cajas de Atención al ciudadano de la Municipalidad o en cualquiera de nuestras Agencias Municipales autorizadas. ");
                $pdf->MultiCell($colCab[3]*5+$colCab[6],5,$texto,0,'L');
                
                
            
                
        $Rs_grabarCAB->pg_Move_Next();
	$NCAB++;
}
		
		
$lw=$marIni;		
//$var1 = $pdf->GetY();				
//$pdf->WriteResumen($lw,$var1, $corte,$topmar);
$pdf->Output();


?>